package ${package}.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import ${package}.entity.${entity};
import ${package}.service.${entity}Service;

@SuppressWarnings("serial")
@Results({
	@Result(name="list", location="${entity?lower_case}_list", type="redirectAction"),
	@Result(name="${entity?lower_case}_list", location="/${entity?lower_case}/${entity?lower_case}_list.jsp", type="redirect"),
	@Result(name="${entity?lower_case}_search", location="/${entity?lower_case}/${entity?lower_case}_edit.jsp", type="redirect")
})
public class ${entity}Action extends BaseAction {

	private ${entity} ${entity?lower_case};
	@Autowired
	private ${entity}Service ${entity?lower_case}Service;
	
	@Action("${entity?lower_case}_add")
	public String add() throws Exception {
		${entity?lower_case}Service.add(${entity?lower_case});
		return "list";
	}
	
	@Action("${entity?lower_case}_list")
	public String list() throws Exception {
		getSession().put("list", ${entity?lower_case}Service.queryAll());
		return "${entity?lower_case}_list";
	}
	
	@Action("${entity?lower_case}_search")
	public String search() throws Exception {
		getSession().put("${entity?lower_case}", ${entity?lower_case}Service.queryById(${entity?lower_case}.getId()));
		return "${entity?lower_case}_search";
	}
	
	@Action("${entity?lower_case}_update")
	public String update() throws Exception {
		${entity?lower_case}Service.update(${entity?lower_case});
		return "list";
	}
	
	@Action("${entity?lower_case}_remove")
	public String remove() throws Exception {
		${entity?lower_case}Service.delete(${entity?lower_case});
		return "list";
	}
	
//	setters and getters

	public void set${entity}(${entity} ${entity?lower_case}) {
		this.${entity?lower_case} = ${entity?lower_case};
	}
	
	public ${entity} get${entity}() {
		return ${entity?lower_case};
	}

}